<template>
  <view class="merchgroup" :style="'padding-top:'+mydata.p_t+'rpx; padding-bottom: '+mydata.p_b+'rpx;'">
	<view class="merchants" :style="'padding: 0px '+mydata.p_lr+'rpx;'">
     <view v-for="(item, i) in list" :key="i" class="item" :style="itemstyle">
        <view :class="'head ' + mydata.list_type">
			<view class="merch-thumb"   :style="mydata.logo_type == 'square' ? 'border-radius: 12rpx' : 'border-radius: 50%;'">
				 <vimage class="img_box" :src="item.logo"  ></vimage>
			</view>
		 
          <view class="content" v-bind:class="mydata.shownum? '':'nonum'">
            <view class="title" :style="'color: '+mydata.title_color+'; margin: 0px;'">
              <text class="merchtitle">{{item.name}}</text>
            </view>
            <text v-if="mydata.shownum" class="subtitle" :style="'color: '+mydata.num_color">在售商品{{item.commodity_count}}件</text>
          </view>
          <view class="distance" style="justify-content: center;" @click="tostore(item.id)">
            <view class="enter-icon-btn" style="" v-if="mydata.btn.type == 3">
              <text class="enter-btn-text" :style="'color: '+mydata.btn.titlecolor1">{{ mydata.btn.title || '进店看看' }}</text>
              <text class="enter-btn-icon" v-bind:class="mydata.btn.icon" :style="'color:'+mydata.btn.icon_color+';background: rgba(0, 0, 0, 0);margin-left:4px'"></text>
            </view>
            <view v-else class="btn" :style="btnstyle">{{ mydata.btn.title || '进店看看' }}</view>
          </view>
        </view>
        <view class="body" v-if="mydata.list_type == 'product'">
          <view  @click="todetial(value.id)" v-if="item.commodity&&item.commodity.length > 0" :class="'merchant ' + (z == 1 ? 'merchant1' : '')" v-for="(value, z) in item.commodity" :key="z" style="width: 212rpx;">
            <view class="img-box" style="width: 212rpx; height: 212rpx;">
              <vimage  :src="value.master" alt="" class="good-img"></vimage>
              <text v-if="mydata.show_type == '2'" class="price" style="color: rgb(255, 255, 255); background: rgba(0, 0, 0, 0.5);">￥{{value.sell_price}}</text>
            </view>
            <view class="good-info" v-if="mydata.show_type == '1'">
              <text class="title" :style="'color:'+mydata.pr_color">{{value.name}}</text>
              <view class="price"><text class="current-price" :style="'color:'+mydata.price_color">￥{{value.sell_price}}</text></view>
            </view>
          </view>
          <view class="no-goods" v-if="item.commodity.length == 0">
            <vimage mode="widthFix"  imgtype="1" src="static/images/noprduct.png" alt="" class="no-goods-img" ></vimage>
            <text class="no-goods-tip">该店铺暂未上架商品</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {mapState, mapMutations} from 'vuex';
export default {
  props: {
    mydata: {
      type: Object,
      default: {}
    }
  },
  data(){
	  return{
		  list:[]
	  }
  },
  watch: {
  	g_id() {
  		this.getlist();
  	}
  },
  computed:{
    itemstyle() {
      return 'background:' + this.mydata.bg_color + ';border-radius:' + this.mydata.r_t + 'rpx ' + this.mydata.r_t+ 'rpx ' + this.mydata.r_b+ 'rpx ' + this.mydata.r_b + 'rpx ';
    },
    btnstyle() {
      if (this.mydata.btn.type == 1) {
        let style =
          'color:' + this.mydata.btn.titlecolor1 + ';background: rgba(0, 0, 0, 0); border: 1px solid ' + this.mydata.btn.color + ';border-radius: ' + this.mydata.btn.rd  + 'rpx;';
        return style;
      } else {
        let style = 'color: ' + this.mydata.btn.titlecolor2 + '; background:' + this.mydata.btn.color + '; border: none; border-radius: ' + this.mydata.btn.rd + 'rpx;';
        return style;
      }

    },
	...mapState({
		g_id:state=>state.g_id
	})
  },
  created() {
		this.getlist()
  },
  methods:{
	  getlist(){
		  let list=this.mydata.list
		  let ids=[]
		  list.forEach(a=>{
			  ids.push(a.id)
		  })
		  let data={
			  ids:JSON.stringify(ids)
		  }
		  this.$http('/merchant/commodity',data,'POST').then(res=>{
			  this.list=res.data.msg
			
		  })
	  },
	  //前往店铺
	  tostore(id) {
	  	this.Jumpurl({
			link:'../merchant/merchant?id=' +id,
			type:1,
			login_type:1
		})
	  },
	  todetial(id){
		  this.Jumpurl({
		  	id:id,
		  	type:2,
		  	login_type:1
		  })
	  },
  }
};
</script>

<style lang="scss" scoped>
.merchgroup {
  width: 100%;
  margin: 0 auto;
  min-height: 200px;
  .merchants {
    margin: 0 auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .item {
      width: 100%;
      display: flex;
      flex-direction: column;
      border-radius: 12rpx;
      margin: 0 auto 16rpx;
      .head {
        display: flex;
        box-sizing: border-box;
        padding: 24rpx;
        flex-wrap: nowrap;
        .merch-thumb {
          width: 80rpx;
          height: 80rpx !important;
          border-radius: 12rpx;
          margin: auto 18rpx auto 0;
		  overflow: hidden;
        }
        .content {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          height: 80rpx;
          margin: auto 0;
          box-sizing: border-box;
          width: 0;
          flex: 1;
          &.nonum{
            justify-content: center;
          }
          .title {
            font-size: 28rpx;
            line-height: 40rpx;
            font-family: PingFang SC;
            font-style: normal;
            font-weight: 600;
            color: #212121;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            display: flex;
            flex-wrap: nowrap;
            .merchtitle {
              display: inline-block;
              flex-grow: 0;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .subtitle {
            font-size: 24rpx;
            line-height: 34rpx;
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            color: #969696;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
        .distance {
          height: 80rpx;
          flex: 0;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .btn {
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            color: #ff3c29;
            font-size: 24rpx;
            padding: 0 22rpx;
            height: 42rpx;
            border: 2px solid #ff3c29;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: center;
            border-radius: 24rpx;
            margin: 0 0 auto auto;
            white-space: nowrap;
          }
          .enter-icon-btn {
            font-size: 28rpx;
            text-align: right;
            display: flex;
            flex-wrap: nowrap;
            white-space: nowrap;
            margin-left: 8rpx;
          }
          .enter-btn-text,
          .enter-btn-icon {
            display: flex;

            flex-direction: column;

            justify-content: center;
            font-size: 28rpx;
            height: 28rpx;
            line-height: 28rpx;
            color: #ff3c29;
            margin: auto 0;
          }
          .closePosition {
            margin: auto;
          }
        }
        &.list {
          .merch-thumb {
            width: 128rpx;
            height: 128rpx !important;
          }
          .content {
            height: 128rpx;
            padding: 4rpx 0;
          }
          .distance {
            height: 128rpx;
          }
        }
      }
      .body {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        padding: 0 24rpx 24rpx;
        flex-wrap: nowrap;
        .merchant {
          width: 212rpx;
          display: flex;
          flex-direction: column;
          &.merchant1 {
            margin: 0 8rpx;
          }
          .img-box {
            width: 212rpx;
            height: 212rpx;
            overflow: hidden;
            border-radius: 12rpx;
            position: relative;
            margin-bottom: 8rpx;
            .good-img {
              width: 100%;
              height: 100%;
            }
            .price {
              position: absolute;
              left: 0;
              bottom: 0;
              height: 34rpx;
              text-align: center;
              background: rgba(0, 0, 0, 0.5);
              border-radius: 0 4rpx 0 0;
              padding: 0 8rpx;
              color: #fff;
              font-size: 24rpx;
              display: flex;
              font-weight: 300;
              flex-direction: column;
              justify-content: center;
            }
          }
          .good-info {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            flex: 1;
            .title {
              width: 100%;
              font-family: PingFang SC;
              font-style: normal;
              font-weight: normal;
              font-size: 28rpx;
              line-height: 40rpx;
              max-height: 80rpx;
              color: #212121;
              margin-bottom: 8rpx;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            .price {
              display: flex;
              flex-wrap: nowrap;
            }
            .current-price {
              font-family: PingFang SC;
              font-style: normal;
              font-weight: 700;
              font-size: 24rpx;
              line-height: 34rpx;
              display: flex;
              align-items: center;
              color: #ff3c29;
              margin: auto 8rpx auto 0;
            }
          }
        }
        .no-goods {
          display: flex;
          width: 100%;
          justify-content: center;
          flex-direction: column;
          .no-goods-img {
           width: 100%;
            margin: 16rpx auto;
          }
          .no-goods-tip {
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            font-size: 24rpx;
            line-height: 34rpx;
            display: flex;
            align-items: center;
            margin: 0 auto 12rpx;
            color: #969696;
          }
        }
      }
    }
  }
}
</style>
